using System.Linq.Expressions;

namespace zhwy.saas.api.Services
{
    /// <summary>
    /// 基础服务接口
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IBaseService<TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// 根据ID获取实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>实体信息</returns>
        Task<TEntity> GetByIdAsync(object id);

        /// <summary>
        /// 获取所有实体列表
        /// </summary>
        /// <returns>实体列表</returns>
        Task<List<TEntity>> GetAllAsync();

        /// <summary>
        /// 分页获取实体列表
        /// </summary>
        /// <param name="predicate">查询条件</param>
        /// <param name="pageIndex">页码，从1开始</param>
        /// <param name="pageSize">每页记录数</param>
        /// <returns>分页数据</returns>
        Task<(List<TEntity> Items, int Total)> GetPagedListAsync(Expression<Func<TEntity, bool>> predicate, int pageIndex, int pageSize);

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体信息</param>
        /// <returns>是否添加成功</returns>
        Task<bool> AddAsync(TEntity entity);

        /// <summary>
        /// 添加实体并返回带有自增ID的实体
        /// </summary>
        /// <param name="entity">实体信息</param>
        /// <returns>添加后的实体（包含自增ID）</returns>
        Task<TEntity> AddEntityAsync(TEntity entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体信息</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateAsync(TEntity entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteAsync(object id);
    }
}